package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "订单管理")
@RestController("AdminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

            @ApiOperation("订单搜索")
            @GetMapping("/conditionSearch")
            public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
    PageResult page= orderService.selectPage(ordersPageQueryDTO);
return  Result.success(page);
}
    /**
     * 取消订单
     *
     * @param cancelReason
     * @param id
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("cancel")
    public Result cacel(String cancelReason,Long id){
        orderService.cancelOrders(cancelReason,id);
        return Result.success();
    }

    /**
     * 查询订单详情
     *
     * @param id
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
public Result<OrderVO> details(@PathVariable Long id) {
        OrderVO details = orderService.details(id);
        return Result.success(details);
    }

    /**
     * 查询各个状态的订单数量统计
     *
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }
}
